<?php

class CSingle {
    private static $_instance = array();

    static public function getInstance($class, $method='', $param=array())
    {
        $identify = $class.$method;
        if (count($param)) {
        	$identify .= serialize($param);
        }
        if(!isset(self::$_instance[$identify])) {
            if(class_exists($class)){
                $o = new $class();
                if(!empty($method) && method_exists($o, $method))
                    self::$_instance[$identify] = call_user_func_array(array(&$o, $method), $param);
                else
                    self::$_instance[$identify] = $o;
            } else {
                echo 'Error, Class of ', $class, ' not exist.';
				exit();
            }
        }
        return self::$_instance[$identify];
    }
}